﻿Imports System.Data.OleDb

Public Class details
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            If Request.Params("ID") = "" Then Response.Redirect("list.aspx")
            Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("fishTankConnection").ConnectionString)
            oleDbConn.Open()
            detailViewDataBind(oleDbConn)
            commentViewDataBind(oleDbConn)
            oleDbConn.Close()
        End If
    End Sub

    Private Sub detailViewDataBind(oleDbConn As System.Data.OleDb.OleDbConnection)
        Dim SqlString As String = "SELECT * FROM AquariumListView WHERE ID=@f1"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", Request.Params("ID"))
        Dim dataReader = cmd.ExecuteReader()
        detailView.DataSource = dataReader
        detailView.DataBind()
    End Sub

    Private Sub commentViewDataBind(oleDbConn As System.Data.OleDb.OleDbConnection)
        Dim SqlString As String = "SELECT * FROM AquariumCommentsView WHERE ID=@f1 ORDER BY CreatedDateTime ASC"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", Request.Params("ID"))
        Dim dataReader = cmd.ExecuteReader()
        commentView.DataSource = dataReader
        commentView.DataBind()
    End Sub
End Class